package com.weiyi.mashangzhu.Utils;

import android.app.Dialog;
import android.content.Context;
import android.support.annotation.DrawableRes;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.weiyi.mashangzhu.R;

public final class ProgressDialog {


    private static Dialog progressDialog;
    private static ProgressBar dialogPb;
    private static TextView dialogMsg;

    /**
     * 加载进度条
     */
    public static void showProgressDialog(Context context) {
        if (progressDialog != null && progressDialog.isShowing()) {
            progressDialog.dismiss();
            progressDialog = null;
        }
        try {
            progressDialog = new Dialog(context, R.style.progress_dialog);
            progressDialog.setContentView(R.layout.progress_dialog);
            dialogPb = (ProgressBar) progressDialog.findViewById(R.id.dialog_pb);
            dialogMsg = (TextView) progressDialog.findViewById(R.id.dialog_msg);
            progressDialog.setCancelable(true);
            progressDialog.show();
        } catch (Exception exception) {
            exception.printStackTrace();
        }
    }

    /**
     * 隐藏进度条
     */
    public static void dismissProgressDialog() {
        if (null != progressDialog && progressDialog.isShowing() == true) {
            progressDialog.dismiss();
            progressDialog = null;
        }
    }

    public static void setDialogResult() {
        if (null != progressDialog && progressDialog.isShowing() == true) {
            dialogPb.setBackgroundResource(R.mipmap.ic_prompt_success);
            dialogPb.setIndeterminateDrawable(null);
            dialogMsg.setText("生成成功\n加载中...");
        }
    }
}
